/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbean;

import entity.TouristAccountEntity;
import entity.PaymentItemEntity;
import entity.StakeholderEntity;
import entity.TransactionsEntity;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import session.stateful.TouristSessionBean;
import session.stateful.StakeholderSessionBeanStateful;
import session.stateful.TransactionSessionBean;

@ManagedBean(name="transactionManagerBean")
@SessionScoped
public class TransactionManagerBean {
    @EJB
    private TransactionSessionBean transactionSessionBean;
    @EJB
    private TouristSessionBean touristSessionBean;
    @EJB
    private StakeholderSessionBeanStateful stakeholderSessionBean;
    private StakeholderEntity selectedStakeholder=null;
    private TouristAccountEntity selectedTourist=null;
    private List<TransactionsEntity> transactionsList;
    private List<TransactionsEntity> touristTransactionsList;
    private List<TransactionsEntity> stakeholderTransactionsList;
    private Date date1;    
    private Date date2; 
    private SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    
    public TransactionManagerBean() {
//        
    }
    public void initTransaction(PhaseEvent event){
        
    }
    public void viewAllTransactions(){
        setTransactionsList(getTransactionSessionBean().getAllTransactions());
        System.out.println(getTransactionsList().size());
    }
    public void viewAllTransactionsByDate(){   
        System.out.println("date1 "+getDate1());
        System.out.println("date2 "+getDate2());
        setTransactionsList(getTransactionSessionBean().getAllTransactionsByDate(getDate1(), getDate2()));          
    }
    public void viewAllTransactionsTourist(){    
        setSelectedTourist((TouristAccountEntity)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("tourist"));
        setTransactionsList(getTransactionSessionBean().getAllTransactionsTourist(getSelectedTourist()));
    }
    public void viewTransactionsTouristByDate(){
        System.out.println("date1 "+getDate1());
        System.out.println("date2 "+getDate2());
        setSelectedTourist((TouristAccountEntity)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("tourist"));
        setTransactionsList(getTransactionSessionBean().getTransactionsTouristByDate(getSelectedTourist(), getDate1(), getDate2()));
    }
    public void viewAllTransactionsStakeholder(){    
        setSelectedStakeholder((StakeholderEntity) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("stakeholder"));
        setTransactionsList(getTransactionSessionBean().getAllTransactionsStakeholder(getSelectedStakeholder()));
    }
    public void viewTransactionsStakeholderByDate(){
        System.out.println("date1 "+getDate1());
        System.out.println("date2 "+getDate2());
        setSelectedStakeholder((StakeholderEntity) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("stakeholder"));
        setTransactionsList(getTransactionSessionBean().getTransactionsStakeholderByDate(getSelectedStakeholder(), getDate1(), getDate2()));
    }

    public TransactionSessionBean getTransactionSessionBean() {
        return transactionSessionBean;
    }

    public void setTransactionSessionBean(TransactionSessionBean transactionSessionBean) {
        this.transactionSessionBean = transactionSessionBean;
    }

    public TouristSessionBean getTouristSessionBean() {
        return touristSessionBean;
    }

    public void setTouristSessionBean(TouristSessionBean touristSessionBean) {
        this.touristSessionBean = touristSessionBean;
    }

    public StakeholderSessionBeanStateful getStakeholderSessionBean() {
        return stakeholderSessionBean;
    }

    public void setStakeholderSessionBean(StakeholderSessionBeanStateful stakeholderSessionBean) {
        this.stakeholderSessionBean = stakeholderSessionBean;
    }

    public StakeholderEntity getSelectedStakeholder() {
        return selectedStakeholder;
    }

    public void setSelectedStakeholder(StakeholderEntity selectedStakeholder) {
        this.selectedStakeholder = selectedStakeholder;
    }

    public TouristAccountEntity getSelectedTourist() {
        return selectedTourist;
    }

    public void setSelectedTourist(TouristAccountEntity selectedTourist) {
        this.selectedTourist = selectedTourist;
    }

    public List<TransactionsEntity> getTransactionsList() {
        return transactionsList;
    }

    public void setTransactionsList(List<TransactionsEntity> transactionsList) {
        this.transactionsList = transactionsList;
    }

    public List<TransactionsEntity> getTouristTransactionsList() {
        return touristTransactionsList;
    }

    public void setTouristTransactionsList(List<TransactionsEntity> touristTransactionsList) {
        this.touristTransactionsList = touristTransactionsList;
    }

    public List<TransactionsEntity> getStakeholderTransactionsList() {
        return stakeholderTransactionsList;
    }

    public void setStakeholderTransactionsList(List<TransactionsEntity> stakeholderTransactionsList) {
        this.stakeholderTransactionsList = stakeholderTransactionsList;
    }

    public Date getDate1() {
        return date1;
    }

    public void setDate1(Date date1) {
        this.date1 = date1;
    }

    public Date getDate2() {
        return date2;
    }

    public void setDate2(Date date2) {
        this.date2 = date2;
    }

    public SimpleDateFormat getSdf() {
        return sdf;
    }

    public void setSdf(SimpleDateFormat sdf) {
        this.sdf = sdf;
    }


}
